package login

import (
	"errors"
	"github.com/gin-gonic/gin"
	"guoquan/model"
	"net/http"
)

func UserLogin(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")

	err := func() error {
		if username == "" {
			return errors.New("用户名不能为空")
		}
		if password == "" {
			return errors.New("密码不能为空")
		}
		return nil
	}()
	if err != nil {
		c.String(http.StatusOK, "错误")
		// c.String(http.StatusOK, lib.JsonResponse(0, err.Error(), ""))
	}

	// password, _ = util.Password([]byte(password))
	user := model.User{
		Username: username,
		Password: password,
	}

	c.String(http.StatusOK, user.Login())
	//c.JSON(http.StatusOK, gin.H{"err": 0, "msg": err})
}
